#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>


int main()
{
    //打开文件
    FILE *fp = fopen("bite", "w");
    if (fp == NULL)
    {
        perror("fopen fail:");
        return 1;
    }

    //向文件写入内容
    const char *message = "linux so easy!";
    fwrite(message, 1, strlen(message), fp);
    fclose(fp);

    fp = fopen("bite", "r");
    if (fp == NULL)
    {
        perror("fopen fail:");
        return 2;
    }

    //改变文件流位置
    int ret_fseek = fseek(fp, 0, SEEK_SET);
    if (ret_fseek != 0)
    {
        perror("fseek fail");
        return 3;
    }

    char buffer[100];
    int n = fread(buffer, 1, strlen(message), fp);
    if (n != 0)
    {
        buffer[strlen(buffer)] = 0;
        printf("%s\n", buffer);
    }

    return 0;
}